﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Web.Services;
using System.Data;
using System.Text;

namespace eTruck.Views.Commons
{
    /// <summary>
    /// Summary description for FormHandler_Car
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class FormHandler_Car : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //try
            //{
            //    string prefixText = context.Request.QueryString["q"];
            //    BLL.Modules bll = new BLL.Modules();
            //    DataSet ds = bll.GetModuleByModuleName(prefixText);
            //    StringBuilder sb = new StringBuilder();
            //    if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            //    {
            //        foreach (DataRow dr in ds.Tables[0].Rows)
            //        {
            //            sb.Append(dr["ModuleID"] + "|" + dr["ModuleName"])
            //            .Append(Environment.NewLine);
            //        }
            //    }
            //    context.Response.Write(sb.ToString());

            //}
            //catch
            //{
            //    context.Response.Write("");
            //}
            try
            {
                string CarNo = context.Request.QueryString["q"];
                CarNo.Replace("'", "");
                BLL.Car bll = new BLL.Car();
                DataSet ds = bll.GetList(" Car_No like '%" + CarNo + "%'");
                StringBuilder sb = new StringBuilder();
                if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        sb.Append(dr["Carid"] + "|" + dr["Car_No"] + "|" + dr["Capacity"] + "|" + dr["Unit"] + "|" + dr["CorporationID"] + "|" + dr["CorporationName"] + "|" + dr["Contact"])
                        .Append(Environment.NewLine);
                    }
                }
                context.Response.Write(sb.ToString());

            }
            catch
            {
                context.Response.Write("");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}